<?php

namespace app\controller\merchant;

use app\BaseController;
use app\model\Account;
use app\model\AccountApply;
use app\model\ScoreUpload;
use app\model\Store;
use app\model\UserScoreRecharge;
use think\response\Json;

class MerchantAccount extends BaseController
{
    public function lst(): Json
    {
        return $this->success($this->app->make(Account::class)->getPage());
    }

    public function store(): Json
    {
        return $this->success($this->app->make(Store::class)->merchantStore());
    }

    public function add(): Json
    {
        if (!$this->request->isPost()) throw new \Exception('请求方式错误', 7001);
        return $this->success($this->app->make(Account::class)->updateOrAdd());
    }

    public function changeState(): Json
    {
        if (!$this->request->isPost()) throw new \Exception('请求方式错误', 7001);
        return $this->success($this->app->make(Account::class)->changeState());
    }

    public function storeAccount(): Json
    {
        return $this->success($this->app->make(Account::class)->searchAccountLst());
    }

    public function addBalance(): Json
    {
        if (!$this->request->isPost()) throw new \Exception('请求方式错误', 7001);
        return $this->success($this->app->make(Account::class)->addBalance());
    }

    public function applyLst(): Json
    {
        return $this->success($this->app->make(AccountApply::class)->getPage());
    }

    public function applyDownload(): Json
    {
        return $this->success($this->app->make(AccountApply::class)->download());
    }

    public function add_payment(): Json
    {
        if (!$this->request->isPost()) throw new \Exception('请求方式错误', 7001);
        return $this->success($this->app->make(UserScoreRecharge::class)->add());
    }

    public function paymentLst(): Json
    {
        return $this->success($this->app->make(UserScoreRecharge::class)->getPage());
    }

    public function refund(): Json
    {
        return $this->success($this->app->make(UserScoreRecharge::class)->refund());
    }

    public function paymentDownload(): Json
    {
        return $this->success($this->app->make(UserScoreRecharge::class)->download());
    }

    public function delete(): Json
    {
        if (!$this->request->isDelete()) throw new \Exception('请求方式错误', 7001);
        return $this->success($this->app->make(Account::class)->deleteAccount());
    }

    public function saveSCoreChange(): Json
    {
        if (!$this->request->isPost()) throw new \Exception('请求方式错误', 7001);
        $data = $this->request->post('balance');
        $this->app->make(ScoreUpload::class)->saveAll($data);
        return $this->success();
    }
}
